import ass from './ass'
export default class {
    static getMonth(date){
        date = ass.createDate(date)
        return date.getMonth() + 1
    }
    /**
     * 返回时间
     * @param {Object|String|Number} date 
     */
    static getTime(date, calSign, hourSign){
        date = ass.createDate(date)
        return this.slice({
            date
        })
    }
    /**
     * 返回年-月-日
     * @param {Object|String|Number} date 
     */
    static getCal(date, sign = '-'){
        date = ass.createDate(date)
        return this.slice({
            date,
            format: [0, 3]
        })
    }
    /**
     * 返回时:分:秒
     * @param {Object|String|Number} date 
     */
    static getHour(date, sign = ':'){
        date = ass.createDate(date)
        return this.slice({
            date,
            format: 3
        })
    }
    /**
     * 
     * @param {Object} param 
     *  @param {Date} date 
     *  @param {Array|Number|String} format 
     *  @param {String} calSign
     *  @param {String} hourSign
     */
    static slice(param) {
        let { date, format, calSign, hourSign } = ass.sliceParam(param)
        const repair = num => num < 10 ? '0' + num : num;
        const aFn = [
            () => date.getFullYear(),
            () => repair(this.getMonth(date)),
            () => repair(date.getDate()),
            () => repair(date.getHours()),
            () => repair(date.getMinutes()),
            () => repair(date.getSeconds()),
        ]
        const styles = [
            calSign,
            calSign,
            ' ',
            hourSign,
            hourSign,
            ''
        ]
        function oFn() {
            let str = '';
            Array.isArray(format) ?
            aFn.slice(format[0], format[1]).forEach((fn, i, arr) => str += arr.length - 1 > i ? fn() + styles[format[0] + i] : fn()) :
            aFn.slice(format).forEach((fn, i) => str += (fn() + styles[format + i]))
            return str;
        }
        return oFn();
    }
    getWeek(date, str = '星期') {
        date = ass.createDate(date)
        let arr = ['日', '一', '二', '三', '四', '五', '六']
        return str + arr[date.getDay()]
    }
    // getWeekDaily(date, str = '星期') {
    //     date = ass.createDate(date)
    //     let nowStamp = Date.now()
    //     let paramStamp = date.getTime()
    //     if(paramStamp > nowStamp){

    //     }
    //     let day = date.getDay()
    //     return b && this.getHour(Date.now()) === this.getHour(date)
    //         ? '今天'
    //         : str + arr[day]
    // }
}